package com.gg.user.gguser.dao;

import com.gg.user.gguser.dataobject.GgSigningDataobject;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GgSigningDaoMapper {

    // 增加 从信息、商机 新增过来的
    @Insert("insert into gg_signing(gg_items_token,gg_s_name,gg_s_province,gg_s_city,gg_s_detailed,gg_s_handle,gg_s_contact,gg_s_state,gg_s_level,gg_s_gender,gg_s_position,gg_s_telephone,gg_s_fax,gg_s_mailbox,gg_s_qq,gg_s_wechat,gg_s_remarks,gg_id,gg_id_user,gg_s_time,gg_s_areaid) values (#{ggItemsToken},#{ggSName},#{ggSProvince},#{ggSCity},#{ggSDetailed},#{ggSHandle},#{ggSContact},#{ggSState},#{ggSLevel},#{ggSGender},#{ggSPosition},#{ggSTelephone},#{ggSFax},#{ggSMailbox},#{ggSQq},#{ggSWechat},#{ggSRemarks},#{ggId},#{ggIdUser},#{ggSTime},#{ggSAreaid})")
    Integer addSignings(@Param("ggItemsToken")String ggItemsToken, @Param("ggSName")String ggSName, @Param("ggSProvince")String ggSProvince, @Param("ggSCity")String ggSCity, @Param("ggSDetailed")String ggSDetailed, @Param("ggSHandle")String ggSHandle, @Param("ggSContact")String ggSContact, @Param("ggSState")Integer ggSState, @Param("ggSLevel")Integer ggSLevel, @Param("ggSGender")String ggSGender, @Param("ggSPosition")String ggSPosition, @Param("ggSTelephone")String ggSTelephone, @Param("ggSFax")String ggSFax, @Param("ggSMailbox")String ggSMailbox, @Param("ggSQq")String ggSQq, @Param("ggSWechat")String ggSWechat, @Param("ggSRemarks")String ggSRemarks, @Param("ggId")String ggId, @Param("ggIdUser")String ggIdUser, @Param("ggSTime")String ggSTime, @Param("ggSAreaid")String ggSAreaid);

    // 删除 签约客户
    @Delete("delete from gg_signing where gg_s_id=#{itemsId}")
    Integer delectSigningsItems(@Param("itemsId")Integer itemsId);

    // 查询详情  单个
    @Select("select gg_items_token as ggItemsToken,gg_s_name as ggSName,gg_s_province as ggSProvince,gg_s_city as ggSCity,gg_s_detailed as ggSDetailed,gg_s_handle as ggSHandle,gg_s_contact as ggSContact,gg_s_state as ggSState,gg_s_level as ggSLevel,gg_s_gender as ggSGender,gg_s_position as ggSPosition,gg_s_telephone as ggSTelephone,gg_s_fax as ggSFax,gg_s_mailbox as ggSMailbox,gg_s_qq as ggSQq,gg_s_wechat as ggSWechat,gg_s_remarks as ggSRemarks,gg_id as ggId,gg_id_user as ggIdUser,gg_s_time as ggSTime, gg_s_areaid as ggSAreaid,gg_s_zipcode as ggSZipcode,gg_s_website as ggSWebsite,gg_s_source as ggSSource  from gg_signing where gg_s_id=#{itemsId}")
    GgSigningDataobject getSigningItems(@Param("itemsId")Integer itemsId);

    // 一共多少个
    @Select({
            "<script>",
            "select count(*) from gg_signing where gg_id_user=#{ggIdUser}",
            "<if test='name!=null and name!=\"\"'>",
            "and gg_s_name like '%${name}%'",
            "</if>",
            "<if test='type!=null and name!=\"\"'>",
            "and gg_s_level = #{type}",
            "</if>",
            "<if test='state!=null and name!=\"\"'>",
            "and gg_s_state = #{state}",
            "</if>",
            "<if test='remarks!=null and name!=\"\"'>",
            "and gg_s_remarks  like '%${remarks}%'",
            "</if>"
            ,"</script>"
    })
    Integer getSigningSelectCount(@Param("ggIdUser")String ggIdUser,@Param("name")String name,@Param("type") Integer type,@Param("state")Integer state,@Param("remarks")String remarks);

    // 列表
    @Select({"<script>",
            "select gg_s_id as ggSId, gg_items_token as ggItemsToken,gg_s_name as ggSName,gg_s_province as ggSProvince,gg_s_city as ggSCity,gg_s_detailed as ggSDetailed,gg_s_areaid as ggSAreaid,gg_s_handle as ggSHandle,gg_s_contact as ggSContact,gg_s_state as ggSState,gg_s_level as ggSLevel,gg_s_gender as ggSGender,gg_s_position as ggSPosition,gg_s_telephone as ggSTelephone,gg_s_fax as ggSFax,gg_s_mailbox as ggSMailbox,gg_s_qq as ggSQq,gg_s_wechat as ggSWechat,gg_s_remarks as ggSRemarks,gg_id as ggId,gg_id_user as ggIdUser,gg_s_time as ggSTime from gg_signing where gg_id_user=#{ggIdUser}",
            "<if test='name!=null and name!=\"\"'>",
            "and gg_s_name like '%${name}%'",
            "</if>",
            "<if test='type!=null and name!=\"\"'>",
            "and gg_s_level = #{type}",
            "</if>",
            "<if test='state!=null and name!=\"\"'>",
            "and gg_s_state = #{state}",
            "</if>",
            "<if test='remarks!=null and name!=\"\"'>",
            "and gg_s_remarks like '%${remarks}%'",
            "</if>",
            "order by gg_s_update desc limit #{page},#{pageNumber}"
            ,"</script>"})
    List<GgSigningDataobject> getSigningSelectList(@Param("page")Integer page, @Param("pageNumber")Integer pageNumber, @Param("ggIdUser")String ggIdUser, @Param("name")String name, @Param("type") Integer type, @Param("state")Integer state, @Param("remarks")String remarks);

    /**
     * 增加签约
     */
    @Insert("insert into gg_signing(gg_items_token,gg_s_name,gg_s_province,gg_s_city,gg_s_areaid,gg_s_detailed,gg_s_handle,gg_s_contact,gg_s_state,gg_s_level,gg_s_gender,gg_s_position,gg_s_telephone,gg_s_fax,gg_s_mailbox,gg_s_qq,gg_s_wechat,gg_s_remarks,gg_id,gg_id_user) values (#{ggItemsToken},#{ggSName},#{ggSProvince},#{ggSCity},#{ggSAreaid},#{ggSDetailed},#{ggSHandle},#{ggSContact},#{ggSState},#{ggSLevel},#{ggSGender},#{ggSPosition},#{ggSTelephone},#{ggSFax},#{ggSMailbox},#{ggSQq},#{ggSWechat},#{ggSRemarks},#{ggId},#{ggIdUser})")
    Integer addSigningsItems(@Param("ggSName")String ggSName, @Param("ggSProvince")String ggSProvince, @Param("ggSCity")String ggSCity,@Param("ggSAreaid")String ggSAreaid, @Param("ggSDetailed")String ggSDetailed, @Param("ggSHandle")String ggSHandle, @Param("ggSContact")String ggSContact, @Param("ggSState")Integer ggSState, @Param("ggSLevel")Integer ggSLevel, @Param("ggSGender")String ggSGender, @Param("ggSPosition")String ggSPosition, @Param("ggSTelephone")String ggSTelephone, @Param("ggSFax")String ggSFax, @Param("ggSMailbox")String ggSMailbox, @Param("ggSQq")String ggSQq, @Param("ggSWechat")String ggSWechat, @Param("ggSRemarks")String ggSRemarks, @Param("ggId")String ggId, @Param("ggIdUser")String ggIdUser, @Param("ggItemsToken")String ggItemsToken);

    // 查看商机详情
    @Select("select gg_s_name as ggSName,gg_s_province as ggSProvince,gg_s_city as ggSCity,gg_s_detailed as ggSDetailed,gg_s_areaid as ggSAreaid,gg_s_handle as ggSHandle,gg_s_contact as ggSContact,gg_s_state as ggSState,gg_s_level as ggSLevel,gg_s_gender as ggSGender,gg_s_position as ggSPosition,gg_s_telephone as ggSTelephone,gg_s_fax as ggSFax,gg_s_mailbox as ggSMailbox,gg_s_qq as ggSQq,gg_s_wechat as ggSWechat,gg_s_remarks as ggSRemarks,gg_id as ggId,gg_id_user as ggIdUser,date_format(gg_s_time, '%Y-%m-%d %h:%m:%s') as ggSTime,date_format(gg_s_update, '%Y-%m-%d %h:%m:%s') as ggSUpdate,gg_s_zipcode as ggSZipcode,gg_s_website as ggSWebsite,gg_s_source as ggSSource from gg_signing where gg_id_user=#{ggIdUser} and gg_items_token=#{token}")
    GgSigningDataobject getSigningSelectItems(@Param("ggIdUser")String ggIdUser, @Param("token")String token);

    // 修改商机信息
    @Update("update gg_signing set gg_s_name=#{ggSName},gg_s_province=#{ggSProvince},gg_s_city=#{ggSCity},gg_s_areaid=#{ggSAreaid},gg_s_detailed=#{ggSDetailed},gg_s_handle=#{ggSHandle},gg_s_contact=#{ggSContact},gg_s_level=#{ggSLevel},gg_s_state=#{ggSState},gg_s_gender=#{ggSGender},gg_s_position=#{ggSPosition},gg_s_telephone=#{ggSTelephone},gg_s_fax=#{ggSFax},gg_s_mailbox=#{ggSMailbox},gg_s_qq=#{ggSQq},gg_s_wechat=#{ggSWechat},gg_s_zipcode=#{ggSZipcode},gg_s_website=#{ggSWebsite},gg_s_source=#{ggSSource} where gg_items_token=#{ggItemsToken} and gg_id_user=#{ggId}")
    Integer updateSigning(@Param("ggItemsToken")String ggItemsToken, @Param("ggSName")String ggSName, @Param("ggSProvince")String ggSProvince, @Param("ggSCity")String ggSCity,@Param("ggSAreaid")String ggSAreaid, @Param("ggSDetailed")String ggSDetailed, @Param("ggSHandle")String ggSHandle, @Param("ggSContact")String ggSContact, @Param("ggSState")Integer ggSState, @Param("ggSLevel")Integer ggSLevel, @Param("ggSGender")String ggSGender, @Param("ggSPosition")String ggSPosition, @Param("ggSTelephone")String ggSTelephone, @Param("ggSFax")String ggSFax, @Param("ggSMailbox")String ggSMailbox, @Param("ggSQq")String ggSQq, @Param("ggSWechat")String ggSWechat, @Param("ggId")String ggId, @Param("ggSZipcode")String  ggSZipcode, @Param("ggSWebsite")String  ggSWebsite, @Param("ggSSource")String  ggSSource);

    // 修改备注
    @Update("update gg_signing set gg_s_remarks=#{count} where gg_items_token=#{token} and gg_id=#{ggId}")
    Integer updateSigningRemarks(@Param("token")String token,@Param("count")String count,@Param("ggId")String ggId);
}
